package com.lv.suyiyong.hfr.adapter

import android.graphics.Color
import android.view.View
import com.chad.library.adapter.base.BaseQuickAdapter
import com.lv.common.base.DataBindBaseViewHolder
import com.lv.common.imp.OnPositionTListener
import com.lv.service.bean.GoodsCategoryAttachedBean
import com.lv.suyiyong.hfr.R
import com.lv.suyiyong.hfr.databinding.ItemCompanyCategoryTabBinding


/**
 * 作者： ygx
 * 创建日期：2022/6/24 8:10 PM
 * 签名： 天行健，君子以自强不息；地势坤，君子以厚德载物。
 *      _              _           _     _   ____  _             _ _
 *     / \   _ __   __| |_ __ ___ (_) __| | / ___|| |_ _   _  __| (_) ___
 *    / _ \ | '_ \ / _` | '__/ _ \| |/ _` | \___ \| __| | | |/ _` | |/ _ \
 *   / ___ \| | | | (_| | | | (_) | | (_| |  ___) | |_| |_| | (_| | | (_) |
 *  /_/   \_\_| |_|\__,_|_|  \___/|_|\__,_| |____/ \__|\__,_|\__,_|_|\___/
 *
 * You never know what you can do until you try !
 * ----------------------------------------------------------------
 *
 */
class CompanyCategoryTabAdapter(
    private val datas: MutableList<GoodsCategoryAttachedBean>,
    private val showTag: Boolean = false
) :
    BaseQuickAdapter<GoodsCategoryAttachedBean, DataBindBaseViewHolder>
        (R.layout.item_company_category_tab, datas) {

    override fun convert(
        holder: DataBindBaseViewHolder,
        item: GoodsCategoryAttachedBean,
        payloads: List<Any>
    ) {
        super.convert(holder, item, payloads)
        val mBinding: ItemCompanyCategoryTabBinding =
            holder.getBind() as ItemCompanyCategoryTabBinding
        mBinding.executePendingBindings()
        mBinding.tvName.setTextColor(
            if (item.selected) Color.parseColor("#eb613d") else Color.parseColor(
                "#242424"
            )
        )
        mBinding.tvName.setBackgroundColor(
            if (item.selected) Color.parseColor("#ffffff") else Color.parseColor(
                "#f9f9f9"
            )
        )
        mBinding.tvName.paint.isFakeBoldText = item.selected
        if (showTag) {
            mBinding.vTag.visibility = if (item.selected) View.VISIBLE else View.GONE
        } else {
            mBinding.vTag.visibility = View.GONE
        }
    }

    override fun convert(holder: DataBindBaseViewHolder, item: GoodsCategoryAttachedBean) {
        val mBinding: ItemCompanyCategoryTabBinding =
            holder.getBind() as ItemCompanyCategoryTabBinding
//        mBinding.itemRoot = item
//        //防止列表闪烁
        mBinding.executePendingBindings()
        val layoutPosition = holder.layoutPosition
        mBinding.tvName.text = item.name
        mBinding.tvName.setTextColor(
            if (item.selected) Color.parseColor("#eb613d") else Color.parseColor(
                "#242424"
            )
        )
        mBinding.tvName.setBackgroundColor(
            if (item.selected) Color.parseColor("#ffffff") else Color.parseColor(
                "#f9f9f9"
            )
        )
        mBinding.tvName.paint.isFakeBoldText = item.selected
        mBinding.clParent.setOnClickListener {
            onViewClickListener?.onClick(layoutPosition, item)
        }
        if (showTag) {
            mBinding.vTag.visibility = if (item.selected) View.VISIBLE else View.GONE
        } else {
            mBinding.vTag.visibility = View.GONE
        }
    }

    var onViewClickListener: OnPositionTListener<GoodsCategoryAttachedBean>? = null


}